<template>
  <el-table :data="model.getList()" style="width: 100%;" @row-click="row => $emit('form', row)">
    <el-table-column :label="plugin.lang('form.code')" prop="code">
      <template #default="scope">
        <el-link type="primary" href="javascript:;">{{ scope.row.code }}</el-link>
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('form.classify_id')" prop="classify_id">
      <template #default="scope">
        {{ scope.row.classify ? scope.row.classify.name : '-' }}
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('form.name')" min-width="150" prop="name">
      <template #default="scope">
        <div class="wrap">
          <Type :type="scope.row.type" />
          {{ scope.row.name }}
        </div>
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('form.phone')" prop="phone" />
    <el-table-column :label="plugin.lang('form.email')" prop="email" />
    <el-table-column :label="plugin.lang('form.point')" prop="point">
      <template #default="scope">
        {{ scope.row.point }}
      </template>
    </el-table-column>
    <el-table-column fixed="right" width="200">
      <template #default="scope">
        <div style="text-align: right">
          <el-dropdown @command="command => $emit(command, scope.row)" style="margin-right: 10px">
            <el-button type="primary" size="small" @click.stop>{{ lang.t('common.active') }}<i class="iconfont mini icon-arrow-down el-icon--right"></i></el-button>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="point">{{ plugin.lang('point.title') }}</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <el-popconfirm
            :title="lang.t('alert.delete')"
            @confirm="model.del(scope.row.id)"
            confirmButtonType="danger"
            placement="left"
            hideIcon
          >
            <template #reference>
              <el-button type="danger" size="small" @click.stop>{{ lang.t('common.delete') }}</el-button>
            </template>
          </el-popconfirm>
        </div>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import app from '@/app'
import model from '../../model'
import Type from '../../components/type'

export default {
  components:{
    Type
  },
  setup() {
    return {
      lang: app.lang,
      plugin: app.plugin.index,
      model,
    }
  }
}
</script>